package org.teameleven.quicken.accounts;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.teameleven.quicken.accounts.stock.CompanyShares;

public class Stocks extends Account {

	private List<CompanyShares> stocks;

	public Stocks(BigDecimal amount, BigDecimal interest) {
		super(amount, interest);
		stocks = new ArrayList<CompanyShares>();
	}

	@Override
	public void payMonthlyBills() {
		// no bills for stocks
	}

	@Override
	public BigDecimal getAmount() {
		BigDecimal total = BigDecimal.ZERO;
		for (CompanyShares stock : stocks) {
			total = total.add(stock.getPriceOfShare().multiply(
					new BigDecimal(stock.getNumberOfShares())));
		}
		return total;
	}

	// spread the amount of deposited over all the shares
	@Override
	public void deposit(BigDecimal deposit) {
		if (new BigDecimal(stocks.size()).signum() != 0) {
			BigDecimal depositAmount = deposit
					.divide(new BigDecimal(stocks.size()));
			for (CompanyShares stock : stocks) {
				int numberOfShares = depositAmount.divide(stock.getPriceOfShare()).ROUND_DOWN;
				stock.setNumberOfShares(stock.getNumberOfShares() + numberOfShares);
			}
		}

	}

	@Override
	public void payBill(BigDecimal amount) {
		// TODO Auto-generated method stub

	}

	@Override
	public void makeMonthlyDeposits() {
		// TODO Auto-generated method stub

	}

}
